<template>
  <div>
    <el-select v-model="sectionIdval" placeholder="请选择年段" class="mr-10 w-140" @change="sectionChange" size="small">
      <el-option :label="item.section_name" :value="item.id" v-for="(item, index) in sectionList"
                 :key="index"></el-option>
    </el-select>
  </div>
</template>
<script>
  import api from '@/utils/api.js'
  import {pagination} from '@/utils/util.js'

  export default {
    name: 'sectioninput',
    props: ['sectionId'],
    data () {
      return {
        sectionList: [],
        sectionIdval: this.sectionId,
        page: {
          pageindex: pagination.pageIndex,
          pagesize: pagination.pageSize,
          total: pagination.total
        }
      }
    },
    watch: {
      sectionId () {
        this.sectionIdval = this.sectionId
      }
    },
    created () {
      this.initFn()
    },
    methods: {
      initFn () {
        this.$fetch(api.user_sectionindex, {p: this.page.pageindex}).then((response) => {
          if (response.code === 0) {
            this.sectionList = response.list.data
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      sectionChange () {
        console.log('变了么', this.sectionIdval)
        this.$emit('update:sectionId', this.sectionIdval)
        // this.$emit('changeSection', this.sectionIdval)
      }
    },
    mounted () {
    }
  }
</script>
